home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 January / macformat-020.iso / Shareware City / Developers / bison-1.22 / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-11  |  3.6 KB  |  149 lines  |  [TEXT/EMAC]

  1. /* Top level entry point of bison,
  2.    Copyright (C) 1984, 1986, 1989 Free Software Foundation, Inc.
  3.  
  4. This file is part of Bison, the GNU Compiler Compiler.
  5.  
  6. Bison is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2, or (at your option)
  9. any later version.
  10.  
  11. Bison is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with Bison; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20.  
  21. #include <stdio.h>
  22. #include "system.h"
  23. #include "machine.h"    /* JF for MAXSHORT */
  24.  
  25. #ifdef THINK_C
  26. #include <console.h>
  27. #endif
  28.  
  29. extern    int lineno;
  30. extern    int verboseflag;
  31.  
  32. /* Nonzero means failure has been detected; don't write a parser file.  */
  33. int failure;
  34.  
  35. /* The name this program was run with, for messages. */
  36. char *program_name;
  37.  
  38. extern void getargs(), openfiles(), reader(), reduce_grammar();
  39. extern void set_derives(), set_nullable(), generate_states();
  40. extern void lalr(), initialize_conflicts(), verbose(), terse();
  41. extern void output(), done();
  42.  
  43.  
  44. /* VMS complained about using `int'.  */
  45. int
  46. main(argc, argv)
  47. int argc;
  48. char *argv[];
  49. {
  50. #ifdef THINK_C
  51.   argc = ccommand(&argv);
  52. #endif
  53.   
  54.   program_name = argv[0];
  55.   failure = 0;
  56.   lineno = 0;
  57.   getargs(argc, argv);
  58.   openfiles();
  59.  
  60.   /* read the input.  Copy some parts of it to fguard, faction, ftable and fattrs.
  61.      In file reader.c.
  62.      The other parts are recorded in the grammar; see gram.h.  */
  63.   reader();
  64.  
  65.   /* find useless nonterminals and productions and reduce the grammar.  In
  66.      file reduce.c */
  67.   reduce_grammar();
  68.  
  69.   /* record other info about the grammar.  In files derives and nullable.  */
  70.   set_derives();
  71.   set_nullable();
  72.  
  73.   /* convert to nondeterministic finite state machine.  In file LR0.
  74.      See state.h for more info.  */
  75.   generate_states();
  76.  
  77.   /* make it deterministic.  In file lalr.  */
  78.   lalr();
  79.  
  80.   /* Find and record any conflicts: places where one token of lookahead is not
  81.      enough to disambiguate the parsing.  In file conflicts.
  82.      Currently this does not do anything to resolve them;
  83.      the trivial form of conflict resolution that exists is done in output.  */
  84.   initialize_conflicts();
  85.  
  86.   /* print information about results, if requested.  In file print. */
  87.   if (verboseflag)
  88.     verbose();
  89.   else
  90.     terse();
  91.  
  92.   /* output the tables and the parser to ftable.  In file output. */
  93.   output();
  94.   done(failure);
  95. }
  96.  
  97. /* functions to report errors which prevent a parser from being generated */
  98.  
  99. void
  100. fatal(s)
  101. char *s;
  102. {
  103.   extern char *infile;
  104.  
  105.   if (infile == 0)
  106.     fprintf(stderr, "fatal error: %s\n", s);
  107.   else
  108.     fprintf(stderr, "\"%s\", line %d: %s\n", infile, lineno, s);
  109.   done(1);
  110. }
  111.  
  112.  
  113. /* JF changed to accept/deal with variable args.
  114.    DO NOT change this to use varargs.  It will appear to work
  115.    but will break on systems that don't have the necessary library
  116.    functions.  This is the ONLY safe way to write such a function.  */
  117. /*VARARGS1*/
  118.  
  119. void
  120. fatals(fmt,x1,x2,x3,x4,x5,x6,x7,x8)
  121. char *fmt;
  122. {
  123.   char buffer[200];
  124.  
  125.   sprintf(buffer, fmt, x1,x2,x3,x4,x5,x6,x7,x8);
  126.   fatal(buffer);
  127. }
  128.  
  129.  
  130. void
  131. toomany(s)
  132. char *s;
  133. {
  134.   char buffer[200];
  135.  
  136.     /* JF new msg */
  137.   sprintf(buffer, "limit of %d exceeded, too many %s", MAXSHORT, s);
  138.   fatal(buffer);
  139. }
  140.  
  141.  
  142. void
  143. berror(s)
  144. char *s;
  145. {
  146.   fprintf(stderr, "internal error, %s\n", s);
  147.   abort();
  148. }
  149.